/**
 * Created by AllanXu on 01/03/2016.
 */
define(function (require) {
	var Vue = require('vue'),
		Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities'),
		id = sessionStorage.id;

	var app = new Vue({
		el: '#uc_outside',
		data: {
			req: {
				shape: '',
				hairStyle: '',
				hairColor: '',
				face: '',
				personality: '',
				looks: '',
				charm: ''
			}
		},
		methods: {
			init: function () {
				app.detail = utilities.base64TojsonObj(sessionStorage.userInfo).detail;

				for (var key in app.req) {
					app.req[key] = app.detail[key];
				}

				_(Config.DICTIONARY, {
					parentId: '478,490,499,510,521,535,546'
				}, function (data) {
					for(var key in data.obj){
						data.obj[key].unshift({id: '', name: '请选择'});
					}
					app.$set('shapeList', data.obj[478]);
					app.$set('hairStyleList', data.obj[490]);
					app.$set('hairColorList', data.obj[499]);
					app.$set('faceList', data.obj[510]);
					app.$set('personalityList', data.obj[521]);
					app.$set('looksList', data.obj[535]);
					app.$set('charmList', data.obj[546]);
				});
			},
			save: function () {
				var req = {};
				for (var key in app.req) {
					req['xgdetail.' + key] = app.req[key];
				}
				req.id = id;
				console.log(req);

				_(Config.SERVICE.USERCENTER.OUTSIDE_SAVE, req, function (data) {
					if (data.code == 200 && data.type === 'SUCCESS') {
						alert('保存成功！');
						utilities.refreshUserInfo(function (data) {
							history.back();
						});
					} else {
						alert(data.errmsg);
					}
				});
			},
			getName: function (arr, id) {
				for (var i = 0; i < arr.length; i++)
					if (arr[i]['id'] == id)
						return arr[i]['name'];
			}
		}
	});
	app.init();
});
